<?php
function view_bckcstudio($config,$param) {
    $db = new db($config);
    $result = $db->query("SELECT * FROM cstudio WHERE 1");
	$desc = $db->query("SELECT * FROM deskripsi WHERE page ='cstudio'");
    $param['cstudio'] = true;
    $param['loggedin'] = true;
    view_backend_header($config, $param);
    //verifikasi isian gunakan javascript
    if (isset($_SESSION['editted'])) {
        echo '<div class="alert alert-warning">'.$_SESSION['editted'].'</div>';
        unset($_SESSION['editted']);
    }
    ?>
	<div>
        <form method="post" action="<?php echo $config['home_url']."backend/edcstudio"?>">
            <div>Deskripsi : <textarea class="descbck" name="desccstudio"><?php echo $desc[0]['deskripsi']; ?></textarea>
            <div><input class="btn" type="submit" value="Ubah" name="ubah" /></div>
        </form>
    </div>
    <h3 onclick="javascript:showHide('works');">Works++</h3>
    <div id="works" style="display:none">
        <form method="post" action="<?php echo $config['home_url']."backend/edcstudioworks"?>">
            <div>Nama Works : <input style="width:400px" type="text" name="namaplus" /></div>
			<!--div>Deskripsi : <textarea class="descbck" name="descplus"></textarea></div-->
            <div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
        </form>
		<div>
			<?php
			echo "<ul>";
			foreach ($result as $res){
				echo "<li><a href=\"javascript:showHide('cs".$res['idCstudio']."');\">".$res['works']."</a> <a href=\"".$config['home_url']."backend/delcstudioworks/".$res['idCstudio']."\">(X)</a>";
				echo "<div style=\"display:none\"id=\"cs".$res['idCstudio']."\">";
					//echo $config['home_url']."backend/kutipan/".$res['idkutipan'];
					echo "<form method=\"post\" action=\"".$config['home_url']."backend/edcstudioworks"."\">";
						echo "<input type=\"hidden\" name=\"id\" value=\"".$res['idCstudio']."\" />";
						echo "<div>Nama works : <input style=\"width:400px\" type=\"text\" name=\"namaed\" value=\"".$res['works']."\" /></div>";
						//echo "<div>Deskripsi : <textarea class=\"descbck\" name=\"desced\">".$res['deskripsi']."</textarea></div>";
						echo "<div><input class=\"btn\" type=\"submit\" value=\"Edit\" name=\"edit\" /></div>";
					echo "</form>";
				?>
					<h4 onclick="javascript:showHide('sub<?php echo  $res['idCstudio']?>');">Sub-Works++</h4>
					<div id="sub<?php echo  $res['idCstudio']?>" style="display:none">
						<form method="post" action="<?php echo $config['home_url']."backend/edsubworks"?>">
							<div>Nama Sub : <input style="width:400px" type="text" name="subplus" /></div>
							<input type="hidden" name="idworks" value="<?php echo $res['idCstudio'] ?>" />
							<!--div>Deskripsi : <textarea class="descbck" name="descplus"></textarea></div-->
							<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
						</form>
					<div>
					<?php
						echo "<ul>";
						$hasils = $db->query("SELECT * FROM sub_works WHERE idWorks = ".$res['idCstudio']);
						foreach ($hasils as $hasil){
							echo "<li><a href=\"javascript:showHide('subw".$hasil['idSubworks']."');\">".$hasil['subw']."</a> <a href=\"".$config['home_url']."backend/delsubworks/".$res['idCstudio']."/".$hasil['idSubworks']."\">(X)</a>";
							echo "<div style=\"display:none\"id=\"subw".$hasil['idSubworks']."\">";
								echo "<form method=\"post\" action=\"".$config['home_url']."backend/edsubworks"."\">";
									echo "<input type=\"hidden\" name=\"id\" value=\"".$hasil['idSubworks']."\" />";
									echo "<div>Nama Sub : <input style=\"width:400px\" type=\"text\" name=\"subed\" value=\"".$hasil['subw']."\" /></div>";
									echo "<div><input class=\"btn\" type=\"submit\" value=\"Edit\" name=\"edit\" /></div>";
								echo "</form>";
					?>
					
						<h4 onclick="javascript:showHide('foto<?php echo $hasil['idSubworks']; ?>');">Foto++</h4>
						<div id="foto<?php echo $hasil['idSubworks']; ?>" style="display:none">
							<form action="<?php echo $config['home_url']."backend/addcstudioworksfoto"?>" method="post" enctype="multipart/form-data">
								<input type="hidden" name="idsubs" value="<?php echo $hasil['idSubworks'] ?>" />
								<input type="hidden" name="idworks" value="<?php echo $res['idCstudio'] ?>" />
								<div>Gambar : <input type='file' name='gambar'/></div>
								<div><input class="btn" type="submit" value="Tambah" name="tambah" /></div>
							</form>
							<div><?php
								$uploaddir = $config['image_path'].'cstudio'.DIRECTORY_SEPARATOR."pre".DIRECTORY_SEPARATOR;
								$cfiles = 0;
								$regex = $uploaddir.$res['idCstudio']."-".$hasil['idSubworks']."-*";
								$limitedext = array("jpg","jpeg","png","bmp");
								//FILTER
								foreach (glob($regex) as $files) {
									$getFile = explode(DIRECTORY_SEPARATOR,$files);
									$file = $getFile[count($getFile)-1];
									$getExt = explode('.',$file);
									$file_ext = $getExt[count($getExt)-1];
									if (in_array($file_ext,$limitedext)) {
										?>
										<div style="float:left">
											<div class='gallery-thumb' id='gallery-thumb-<?php echo $cfiles; ?>' style='max-width:80px;max-height:50px;overflow:hidden;'>
												<img id="gallery-thumb-img-<?php echo $cfiles; ?>" src="<?php echo $config['image_url']."cstudio/pre/".$file; ?>" alt="<?php echo $file; ?>" /></a>
											</div>
											<div align="center">
												<div><a class="ahapus" href="<?php echo $config['home_url']."backend/delcstudioworksfoto?img=$file"?>">(X)</a></div>
											</div>
										</div>
										<?php
										$cfiles++;
									}
								}
								if ($cfiles<1){
									echo '<div class="judul-gale"><h5>Tidak terdapat foto saat ini</h5></div>';
								}?>
								<div style="clear:both"></div>
							</div>
						</div>
					<?php	
							echo "</div></li>";
						}
						echo "</ul>";
					?>
				<?php
				echo "</div></li>";
			}
			echo "</ul>";
			?>
		</div>
	</div>
    <?php
    view_backend_footer($config, $param);
}
